package org.aplikator.client.local.widgets;

import com.github.gwtbootstrap.client.ui.TextArea;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import org.aplikator.client.shared.descriptor.PropertyDTO;

public class TextAreaWidget extends DataFieldBase implements DataField<String> {
    private TextArea area = new TextArea();

    public TextAreaWidget(String caption, PropertyDTO property, int size, int rows) {
        super(caption, property);
        controls.add(area);
        //area.addStyleName(PaneWidgetResources.INSTANCE.css().formData());
        area.addValueChangeHandler(new ValueChangeHandler<String>() {
            public void onValueChange(ValueChangeEvent<String> event) {
                setDirty(true);
            }
        });
        if (property.getRefferedThrough() != null) {
            this.setEnabled(false);
        }
        if (size >0) {
            area.setSize(size);
        } else {
            area.setSize(12);
        }

        if (rows > 0) {
            area.setVisibleLines(rows);
        } else {
            area.setVisibleLines(4);
        }
    }

    public void setValue(String value) {
        area.setValue(value);
    }

    public String getValue() {
        return new String(area.getValue());
    }

     public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) {
        return area.addValueChangeHandler(handler);
    }

    public void setEnabled(boolean enabled) {
        area.setEnabled(enabled);
    }



}
